<?php 
    defined('_JEXEC') or die('Restricted access');
	jimport('joomla.application.component.model');
	class work_pointModelreport extends JModel
	{
	   function thong_ke_date_di_tre($date)
       {       
            //dinh dang lai $date giong voi CSDL 
                $d = substr($date,3,2);
                $m = substr($date,0,2);
                $y = substr($date,6,4);
                $date = $y."-".$m."-".$d;
        $db = JFactory::getDBO();
        //truong hop di tre
        if($_SESSION['id_a_b']==0)
        {
            $sql = "select pf.id_employee, us.name, ts.Time, ws.intime, us.id, ab.id_a_b, ts.type_in_out, ts.id
                                FROM #__erp_employee_profile pf
                                LEFT JOIN #__erp_agent_branch_user ab
        	                    ON pf.id = ab.id_user
                                INNER JOIN #__users us
                                on pf.id = us.id
                                INNER JOIN #__erp_timesheet ts
                                on pf.id = ts.id_user
                                INNER JOIN #__erp_employee_workshifts ws
                                ON ws.id = pf.id_work_shifts  
                                Where ts.Time LIKE '$date%'
                                and ts.type_in_out = 0
                                order by us.id , ts.time 
                            ";
            $db->setQuery($sql);
            //print_r($db);die;
        }
        else
        {
            $sql = "select pf.id_employee, us.name, ts.Time, ws.intime, us.id, ab.id_a_b, ts.type_in_out, ts.id
                                FROM #__erp_employee_profile pf
                                LEFT JOIN #__erp_agent_branch_user ab
        	                    ON pf.id = ab.id_user
                                INNER JOIN #__users us
                                on pf.id = us.id
                                INNER JOIN #__erp_timesheet ts
                                on pf.id = ts.id_user
                                INNER JOIN #__erp_employee_workshifts ws
                                ON ws.id = pf.id_work_shifts  
                                Where ts.Time LIKE '$date%'
                                and ab.id_a_b = '".$_SESSION['id_a_b']."'
                                and ts.type_in_out = 0
                                order by us.id , ts.time 
                            ";
            $db->setQuery($sql);
        }
        return $db->loadObjectList();
       }
       
       function thong_ke_date_ve_som($date)
       {       
            //dinh dang lai $date giong voi CSDL 
                $d = substr($date,3,2);
                $m = substr($date,0,2);
                $y = substr($date,6,4);
                $date = $y."-".$m."-".$d;
                $db = JFactory::getDBO();
                //truong hop ve som
        if($_SESSION['id_a_b']==0)
        {
            $sql = "select pf.id_employee, us.name, ts.Time, ws.outtime, us.id, ab.id_a_b, ts.type_in_out, ts.id
                                FROM #__erp_employee_profile pf
                                LEFT JOIN #__erp_agent_branch_user ab
        	                    ON pf.id = ab.id_user
                                INNER JOIN #__users us
                                on pf.id = us.id
                                INNER JOIN #__erp_timesheet ts
                                on pf.id = ts.id_user
                                INNER JOIN #__erp_employee_workshifts ws
                                ON ws.id = pf.id_work_shifts  
                                Where ts.Time LIKE '$date%'
                                and ts.type_in_out = 1
                                order by us.id desc, ts.time desc
                            ";
            $db->setQuery($sql);
            //print_r($db);die;
        }
        else
        {
            $sql = "select pf.id_employee, us.name, ts.Time, ws.outtime, us.id, ab.id_a_b, ts.type_in_out, ts.id
                                FROM #__erp_employee_profile pf
                                LEFT JOIN #__erp_agent_branch_user ab
        	                    ON pf.id = ab.id_user
                                INNER JOIN #__users us
                                on pf.id = us.id
                                INNER JOIN #__erp_timesheet ts
                                on pf.id = ts.id_user
                                INNER JOIN #__erp_employee_workshifts ws
                                ON ws.id = pf.id_work_shifts  
                                Where ts.Time LIKE '$date%'
                                and ab.id_a_b = '".$_SESSION['id_a_b']."'
                                and ts.type_in_out = 1
                                order by us.id desc, ts.time desc
                            ";
            $db->setQuery($sql);
        }
        return $db->loadObjectList();
        }
	}
?>